package com.project.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.server.entity.ArticleCategory;
import com.project.server.mapper.ArticleCategoryMapper;
import com.project.server.service.ArticleCategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory> implements ArticleCategoryService {

    @Override
    public IPage<ArticleCategory> page(Integer current, Integer size, String name, Integer status) {
        Page<ArticleCategory> page = new Page<>(current, size);

        LambdaQueryWrapper<ArticleCategory> wrapper = new LambdaQueryWrapper<ArticleCategory>()
            .like(StringUtils.isNotBlank(name), ArticleCategory::getName, name)
            .eq(status != null, ArticleCategory::getStatus, status)
            .orderByAsc(ArticleCategory::getSort);

        return this.page(page, wrapper);
    }
}
